using System;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;

using WHC.Pager.Entity;
using Microsoft.Practices.EnterpriseLibrary.Data;
using WHC.Hotel.Entity;
using WHC.Hotel.IDAL;
using WHC.OrderWater.Commons;

namespace WHC.Hotel.DAL
{
	/// <summary>
	/// RoomTempDiscount 的摘要说明。
	/// </summary>
	public class RoomTempDiscount : BaseDAL<RoomTempDiscountInfo>, IRoomTempDiscount
	{
		#region 对象实例及构造函数

		public static RoomTempDiscount Instance
		{
			get
			{
				return new RoomTempDiscount();
			}
		}
		public RoomTempDiscount() : base("TB_RoomTempDiscount","ID")
		{
		}

		#endregion

		/// <summary>
		/// 将DataReader的属性值转化为实体类的属性值，返回实体类
		/// </summary>
		/// <param name="dr">有效的DataReader对象</param>
		/// <returns>实体类对象</returns>
		protected override RoomTempDiscountInfo DataReaderToEntity(IDataReader dataReader)
		{
			RoomTempDiscountInfo roomTempDiscountInfo = new RoomTempDiscountInfo();
			SmartDataReader reader = new SmartDataReader(dataReader);
			
			roomTempDiscountInfo.ID = reader.GetInt32("ID");
			roomTempDiscountInfo.Order_ID = reader.GetInt32("Order_ID");
			roomTempDiscountInfo.DiscountRate = reader.GetDouble("DiscountRate");
			roomTempDiscountInfo.CreateDate = reader.GetDateTime("CreateDate");
			roomTempDiscountInfo.OrderType = reader.GetString("OrderType");
            roomTempDiscountInfo.RoomNo = reader.GetString("RoomNo");
			
			return roomTempDiscountInfo;
		}

		/// <summary>
		/// 将实体对象的属性值转化为Hashtable对应的键值
		/// </summary>
		/// <param name="obj">有效的实体对象</param>
		/// <returns>包含键值映射的Hashtable</returns>
        protected override Hashtable GetHashByEntity(RoomTempDiscountInfo obj)
		{
		    RoomTempDiscountInfo info = obj as RoomTempDiscountInfo;
			Hashtable hash = new Hashtable(); 
			
 			hash.Add("Order_ID", info.Order_ID);
 			hash.Add("DiscountRate", info.DiscountRate);
 			hash.Add("CreateDate", info.CreateDate);
 			hash.Add("OrderType", info.OrderType);
            hash.Add("RoomNo", info.RoomNo);
 				
			return hash;
		}

        /// <summary>
        /// 根据订单类型（客房、KTV、茶室）获取对应的房间临时打折信息
        /// </summary>
        /// <param name="OrderType"></param>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public RoomTempDiscountInfo GetDiscount(string OrderType, int orderId, string RoomNo)
        {
            string condition = string.Format("OrderType='{0}' AND Order_ID={1} And RoomNo='{2}' ",
                OrderType, orderId, RoomNo);
            return base.FindSingle(condition);
        }
    }
}